<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教学管理系统 - 登录</title>
    <!-- 引入Vue.js 2 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <!-- 引入Tailwind CSS -->
    <script src="https://cdn.tailwindcss.com"></script>
    <!-- 引入Font Awesome -->
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script>
        tailwind.config = {
            darkMode: 'class',
            theme: {
                extend: {
                    colors: {
                        primary: '#165DFF',
                        secondary: '#36CFC9',
                        success: '#52C41A',
                        warning: '#FAAD14',
                        danger: '#FF4D4F',
                        info: '#8C8C8C',
                        'bg-light': '#F5F7FA',
                        'bg-dark': '#1D2129',
                    },
                    fontFamily: {
                        inter: ['Inter', 'system-ui', 'sans-serif'],
                    },
                    boxShadow: {
                        'card': '0 4px 20px rgba(0, 0, 0, 0.08)',
                        'card-hover': '0 8px 30px rgba(0, 0, 0, 0.12)',
                        'nav': '0 4px 20px rgba(0, 0, 0, 0.05)',
                    },
                    animation: {
                        'gradient': 'gradient 6s linear infinite',
                        'float': 'float 6s ease-in-out infinite',
                        'fade-in': 'fadeIn 0.5s ease-in-out',
                        'slide-up': 'slideUp 0.5s ease-out',
                    },
                    backgroundImage: {
                        'gradient-primary': 'linear-gradient(45deg, var(--tw-gradient-from), var(--tw-gradient-to))',
                    },
                },
            }
        }
    </script>
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }

            .animate-float {
                animation: float 6s ease-in-out infinite;
            }

            .animate-fade-in {
                animation: fadeIn 0.5s ease-in-out;
            }

            .animate-slide-up {
                animation: slideUp 0.5s ease-out;
            }

            .card-shadow {
                box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05);
            }

            .text-gradient {
                background-clip: text;
                -webkit-background-clip: text;
                -webkit-text-fill-color: transparent;
            }

            .bg-blur {
                backdrop-filter: blur(8px);
            }

            .scrollbar-hide::-webkit-scrollbar {
                display: none;
            }

            .hover-trigger .hover-target {
                opacity: 0;
                transform: translateX(-10px);
                transition: all 0.3s ease;
            }

            .hover-trigger:hover .hover-target {
                opacity: 1;
                transform: translateX(0);
            }
        }

        @keyframes gradient {
            0% {
                background-position: 0% 50%;
            }

            50% {
                background-position: 100% 50%;
            }

            100% {
                background-position: 0% 50%;
            }
        }

        @keyframes float {
            0% {
                transform: translateY(0px);
            }

            50% {
                transform: translateY(-10px);
            }

            100% {
                transform: translateY(0px);
            }
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
            }

            to {
                opacity: 1;
            }
        }

        @keyframes slideUp {
            from {
                transform: translateY(20px);
                opacity: 0;
            }

            to {
                transform: translateY(0);
                opacity: 1;
            }
        }
    </style>
    <style>
        body {
            background-color: #F5F7FA;
        }

        .login-container {
            background: rgba(255, 255, 255, 0.9);
            border-radius: 16px;
            box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(5px);
            -webkit-backdrop-filter: blur(5px);
            border: 1px solid rgba(255, 255, 255, 0.3);
        }

        .input-field {
            transition: all 0.3s ease;
        }

        .input-field:focus {
            border-color: #165DFF;
            box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.25);
        }

        .button {
            transition: all 0.3s ease;
        }

        .button:hover {
            transform: translateY(-2px);
        }

        .student-icon {
            color: #165DFF;
            animation: float 3s ease-in-out infinite;
        }
    </style>
</head>

<body class="min-h-screen flex items-center justify-center font-inter bg-bg-light dark:bg-bg-dark transition-colors duration-300">
<div id="app" class="login-container p-6 rounded-3xl shadow-2xl w-full max-w-3xl">
    <div class="flex flex-col md:flex-row">
        <!-- 左侧：学生图标区域 -->
        <div class="flex-1 flex flex-col items-center justify-center p-8 border-b md:border-b-0 md:border-r border-gray-200">
            <div class="student-icon text-[120px] mb-4">
                <i class="fa fa-graduation-cap"></i>
            </div>
            <h2 class="text-2xl font-bold text-center text-gray-700">教学管理系统</h2>
            <p class="text-center text-gray-500 mt-2">高效、安全的教学管理平台</p>
        </div>

        <!-- 右侧：登录表单区域 -->
        <div class="flex-1 p-8">
            <h3 class="text-xl font-bold text-center text-gray-800 mb-6">用户登录</h3>
            <form @submit.prevent="handleLogin">
                <div class="mb-6">
                    <label for="username" class="block text-base font-medium text-gray-700 mb-2">用户名</label>
                    <div class="relative">
                            <span class="absolute inset-y-0 left-0 flex items-center pl-3 text-gray-500">
                                <i class="fa fa-user"></i>
                            </span>
                        <input
                                type="text"
                                id="username"
                                v-model="form.username"
                                class="input-field w-full pl-10 pr-4 py-3 border border-gray-300 rounded-lg focus:outline-none"
                                required
                                placeholder="请输入用户名"
                        >
                    </div>
                </div>
                <div class="mb-6">
                    <label for="password" class="block text-base font-medium text-gray-700 mb-2">密码</label>
                    <div class="relative">
                            <span class="absolute inset-y-0 left-0 flex items-center pl-3 text-gray-500">
                                <i class="fa fa-lock"></i>
                            </span>
                        <input
                                type="password"
                                id="password"
                                v-model="form.password"
                                class="input-field w-full pl-10 pr-4 py-3 border border-gray-300 rounded-lg focus:outline-none"
                                required
                                placeholder="请输入密码"
                        >
                    </div>
                </div>
                <div class="flex items-center justify-between mb-6">
                    <div class="flex items-center">
                        <input id="remember-me" type="checkbox"
                               v-model="form.rememberMe"
                               class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded">
                        <label for="remember-me" class="ml-2 block text-sm text-gray-700">记住我</label>
                    </div>
                    <a href="#" class="text-sm font-medium text-blue-600 hover:text-blue-500">忘记密码?</a>
                </div>
                <button
                        type="submit"
                        class="button w-full bg-primary text-white py-3 px-4 rounded-lg hover:bg-primary/90 mb-4"
                >
                    <i class="fa fa-sign-in mr-2"></i>登录
                </button>
                <div class="flex items-center justify-center">
                    <span class="text-sm text-gray-600">还没有账号?</span>
                    <button
                            type="button"
                            @click="goToRegister"
                            class="ml-2 text-sm font-medium text-primary hover:text-primary/80"
                    >
                        立即注册
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script src="/static/js/message.js"></script>
<script src="/static/js/axios.min.js"></script>
<script src="/static/js/common.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            form: {
                username: '',
                password: '',
                rememberMe: false // 声明记住我状态
            },
        },
        mounted() {
            this.loadFromCookie(); // 页面加载时读取 Cookie
        },
        methods: {
            async handleLogin() {
                if (!this.form.username || !this.form.password) {
                    message.error('请输入账号密码');
                    return;
                }
                const response = await axios.post('/login', this.form);
                sessionStorage.setItem('user-info', JSON.stringify(response.user));
                sessionStorage.setItem('token',response.token)
                message.success('登录成功');
                setTimeout(() => {
                    window.location = '/';
                }, 1500);
            },
            goToRegister() {
                window.location.href = '/register';
            },
            loadFromCookie() {
                const username = decodeURIComponent(this.getCookie('username')) || '';
                const password = decodeURIComponent(this.getCookie('password')) || '';
                // 只有当用户名和密码都存在时，才填充表单
                if (username && password) {
                    this.form.username = username;
                    this.form.password = password;
                    this.form.rememberMe = true; // 自动勾选复选框
                }
            },
            // 辅助函数：获取 Cookie 值
            getCookie(name) {
                const value = `; ${document.cookie}`;
                const parts = value.split(`; ${name}=`);
                return parts.length === 2 ? parts.pop().split(';').shift() : '';
            }
        }
    });
</script>
</html>